<?php
/**
 * Created by b17
 * 2/21/12 8:48 PM
 */

class Zend_View_Helper_Curl extends Zend_View_Helper_Abstract
{
    /**
     * Урл для пагинатора.
     *
     * @param $page
     */
    public function curl($params)
    {
        $request = \Zend_Controller_Front::getInstance()->getRequest();
        $action = $request->getActionName();
        $controller = $request->getControllerName();
        $method = 'get' . $controller . $action;
        if (method_exists($this, $method)) {
            $url = call_user_func(array($this, $method), $params['page']);
        } else {
            $requestParams = $request->getParams();
            $requestParams['page'] = $params['page'];
            $url = $this->view->url($requestParams);
        }
        return $url;
    }

    /**
     * Url для IndexController indexAction
     */
    private function getIndexIndex($page)
    {
        return "/page/{$page}";
    }

    /**
     * Пагинатор для новостей на главной.
     *
     * @param $page
     */
    private function getIndexAllnews($page)
    {
        return $this->view->url(array('page' => $page), 'news_p');
    }

    /**
     *
     * SearchController newsAction
     */
    private function getSearchNews($page)
    {
        $query = \Zend_Controller_Front::getInstance()->getRequest()->getParam('q', 'none');
        $url = $this->view->url(array('controller' => 'search', 'action' => 'news', 'q' => $query, 'page' => $page));
        return $url;
    }
}
